package com.lfy.kcat.workflow.controller;

import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.repository.Deployment;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.dromara.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 *
 * 流程部署
 *
 * @author leifengyang
 * @version 1.0
 * @date 2025/9/10 14:10
 * @description:
 */
@RequestMapping("/workflow")
@RestController
public class ProcessDeployController {


    @Autowired
    RepositoryService repositoryService;

    @PostMapping("deploy")
    public R deployProcess(@RequestParam("file") MultipartFile file) throws IOException {

        Deployment deploy = repositoryService.createDeployment()
            .addInputStream(file.getOriginalFilename(), file.getInputStream())
            .deploy();
        //返回流程定义id
        return R.ok("success",deploy.getId());
    }
}
